package gui.utils;

import core.para.Para;
import gui.win.initializer.Initializer;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class Slider extends JPanel implements ChangeListener{

    public JSlider slider;
    private int which;
    public static int MNRL = 0;
    public static int MNTLEN = 1;
    public static int TRDS = 2;
    public static int SEARCH_DEPTH = 3;
    //public static int NO_OF_SEEDS = 4;
    public static int CLUST_SEQ_KT_TRANS = 5;
    
    public static int MEMORY_IN_GIGS = 6;

    private SliderWrap wrap;

    public Slider(int which, int maxVal, int minVal, int initialVal, int width, SliderWrap os){
        super();
        this.setOpaque(false);
        this.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
        wrap = os;
        this.setLayout(new BorderLayout());
        this.setBorder(null);
        this.which = which;

        slider = new JSlider(SwingConstants.HORIZONTAL, minVal, maxVal, initialVal);
        slider.setOpaque(false);
        slider.setPaintTicks(false);
        slider.setPaintLabels(false);
        slider.setPaintTrack(true);

        slider.addChangeListener(this);
        slider.setPreferredSize(new Dimension(width, 21));
        this.add(slider, BorderLayout.EAST);

        setVisible(true);
    }


    public void stateChanged(ChangeEvent event){
        if(which==MNRL){wrap.setLabel(Para.MNRL = slider.getValue());Initializer.setCommand(this.getClass());}
        if(which==MNTLEN){wrap.setLabel(Para.MNTLEN = slider.getValue());Initializer.setCommand(this.getClass());}
        else if(which==TRDS){wrap.setLabel(Para.TRDS = slider.getValue());Initializer.setCommand(this.getClass());}
        else if(which==MEMORY_IN_GIGS){wrap.setLabel(Para.MEMORY_IN_GIGS = slider.getValue());Initializer.setCommand(this.getClass());}
        else if(which==SEARCH_DEPTH){wrap.setLabel(Para.SD = slider.getValue());Initializer.setCommand(this.getClass());}
        //if(which==NO_OF_SEEDS){wrap.setLabel(Para.NO_OF_SEEDS = slider.getValue());Initializer.setCommand(this.getClass());}
        else if(which==CLUST_SEQ_KT_TRANS){wrap.setLabel(Para.CLUST_SEQ_KT_TRANS = slider.getValue());Initializer.setCommand(this.getClass());}
        //else if(which==SEQSIZE){
        //    Borders.SEQFONTSIZE = slider.getValue();
        //    Borders.setCharHeightAndWidth();
        //    center.updateTable();
        //    center.updatePlots();
        //    try{center.updateReads();}catch(Exception e){}
        //    center.refreshContainer();
        //}
    }
}